//
//  TextView.swift
//  weiboSwift1.0
//
//  Created by xuNick on 16/4/26.
//  Copyright © 2016年 NN. All rights reserved.
//

import UIKit

class TextView: UITextView {
    
    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
      //MARK: - 
    private func setupUI(){
        
        
        // 拖动的时候消失键盘 (系统会弹出警告)
        keyboardDismissMode = .OnDrag
        // 开启垂直方向的弹簧效果
        alwaysBounceVertical = true
        self.addSubview(label!)
        
         NSNotificationCenter.defaultCenter().addObserver(self, selector: "textDidChage", name: UITextViewTextDidChangeNotification, object: nil)
    }

    
    
    
    @objc private func textDidChage(){
        label?.hidden = hasText()
    }
    
    
    //MARK: -  懒加载控件
    lazy var label:UILabel? = {
    let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 12, preferredMaxLayoutWidth: KscreenWidth - 5)
        
        label.frame = CGRect(x: 0, y: 5, width: 0, height: 0)
        label.text = "想说些什么呢"
        label.sizeToFit()
        return label
    }()
    
    
    
    
    
    
    
    
}
